import axios from 'axios';

const fetch = (options = {}) => {
  let {
    method = 'get',
    header = {},
    data,
    url,
  } = options

  switch (method.toLowerCase()) {
    case 'get':
      return axios.get(url, {
        params: data,
        headers: {...header},
      },)
    case 'delete' :
      return axios.delete(url, {
        data: data,
        headers: {...header}
      })
    case 'post' :
      return axios.post(url, data, {
        headers: {...header}
      })
    case 'put' :
      return axios.put(url, data, {
        headers: {...header}
      })
    case 'patch':
      return axios.patch(url, data, {
        headers: {...header}
      })
    default:
      return axios(options)
  }
}

export default async function request(options) {
    try {
        const response = await fetch(options);
        console.log("response", response);
        return {success: false, ...response}
      } catch (error) {
        return {success: false, msg: error}
      }
}